{% extends "admin.html" %}
{% block body %}
<div class="admin">
    <form role="form" id='test' action="/admin" method="post">
        <h1>基本信息设定：</h1>
    <table class="table">
        <tr><td style="width: 15%">站点标题：</td><td><input name="name" class="form-control"type="text" value="{{ name }}"></td>
            <td><p class="text-success">站点主标题</p></td>
        </tr>
        <tr><td>副标题：</td><td><input name="subtitle" class="form-control" type="text" value="{{ subtitle }}"></td>
            <td><p class="text-success">站点副标题</p></td>
        </tr>
        <tr><td>描述信息：</td><td><input name="description" class="form-control" type="text" value="{{ description }}"></td>
            <td><p class="text-success">描述（description）信息</p></td>
        </tr>
        <tr><td>关键字：</td><td><input name="keywords" class="form-control" type="text" value="{{ keywords }}"></td>
            <td><p class="text-success">关键字（keywords）信息</p></td>
        </tr>
        <tr><td>多说ID：</td><td><input name="duoshuo" class="form-control" type="text" value="{{ duoshuo }}"></td>
            <td><p class="text-success">多说留言板系统的注册ID，不了解？<a href="http://duoshuo.com/" target="_blank">-点这里-</a></td>
        </tr>
        <tr><td>{% raw xsrf_form_html() %}</td><td><button class="btn btn-success">提交</button></td></tr>
    </table>
    </form>

        <h1>链接设定：</h1>
    <table class="table table-bordered">
        <tr><td>ID</td><td style="width: 15%">名称</td><td>网址</td><td><a href="#" onclick="link('add','','','')"><span class="glyphicon glyphicon-plus"></span></a></td></tr>
        {% for i in link.keys() %}
            <tr>
                <td  style="width: 15%">{{ i }}</td>
                <td>{{ link[i][0] }}</td>
                <td>{{ link[i][1] }}</td>
                <td><a href="#" onclick="link('del','{{ i }}','{{ link[i][0] }}','{{ link[i][1] }}')"><span class="glyphicon glyphicon-trash"></span></a>
                    <a href="#" onclick="link('edit','{{ i }}','{{ link[i][0] }}','{{ link[i][1] }}')"><span class="glyphicon glyphicon-pencil"></span></a>
                </td>
            </tr>
        {% end %}
    </table><br>

</div>

 <!-- 链接管理 -->
  <div id="editlink" class="modal fade">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
        <h4  id="handle" class="modal-title">编辑：</h4>
      </div>
      <div class="modal-body">
        <input type="hidden" id='linkid' value=""/>
        <input type="hidden" id='method' value=""/>
        <input type="text" id="linkname" name="linkname" class="form-control" placeholder="" required>
        <input type="text" id="linkurl" name="linkurl" class="form-control" placeholder="" required>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        <button id='linksub' type="button" class="btn btn-primary">提交</button>
      </div>
    </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div><!-- /.modal -->
{% end %}

{% block js %}
<script src="static/js/jquery.cookie.js"></script>
<script>
    var xsrf=$.cookie('_xsrf')
    function link(type,id,name,url) {
        if (type=='del'){
            var msg="确定要删除" +name+"吗？\n注意：删除后将无法恢复！"
            if (confirm(msg)){
                $.post('link',{_xsrf:xsrf,id:id,type:'del'},function (data) {alert(data)})
            }
        } else if (type=='edit') {
            $("#linkname").val(name)
            $("#linkurl").val(url)
            $("#linkid").val(id)
            $("#editlink").modal();
        } else if (type=='add') {
            $("#linkname").val("")
            $("#linkurl").val("")
            $("#handle").val("新增链接：")
            $("#method").val("add")
            $("#editlink").modal();
        }
    }
    $('#linksub').click(function () {
        $("#editlink").modal('hide');
        $.post('link',{_xsrf:xsrf,
            id:$("#linkid").val(),
            type:$("#method").val(),
            linkurl:$("#linkurl").val(),
            linkname:$("#linkname").val()},function (data) {
            alert(data);
            location.reload();
        })
    })
</script>
{% end %}